#ifndef __BSP_BUZZER_H
#define __BSP_BUZZER_H

#include "gd32f4xx.h"

#ifndef u16
#define u16 uint16_t
#endif

#ifndef u8
#define u8 uint8_t
#endif

#ifndef SYS_SUPPORT_OS
// GPIO
#define TIMER_GPIO      RCU_GPIOB, GPIOB, GPIO_PIN_9, GPIO_AF_1
// TIMER
#define TIMER_RCU    RCU_TIMER1
#define TIMER_PERIPH TIMER1
#define TIMER_CH     TIMER_CH_1

// 100us , 10us 90us
// PWM （确保 FREQ * PRESCALER > 3662)
#define PRESCALER 10
// #define FREQ					1000
// #define PERIOD				SystemCoreClock / (FREQ * PRESCALER)

// 按照指定频率播放
void buzzer_play(u16 hz_val);

// 按照指定的音调播放 1,2,3,4，..7
void buzzer_beep(u8 hz_val_index);

// 停止播放
void buzzer_stop();

#else

#define BUZZER_RCU      RCU_GPIOB
#define BUZZER_PORT     GPIOB
#define BUZZER_PIN      GPIO_PIN_9

#endif

// 初始化蜂鸣器
void buzzer_init();
void vBeepTask(void* pvDistance);


#endif